#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_clicked()
{
    // 获取时间
    QDateTime timeOld = ui->dateTimeEdit->dateTime();
    QDateTime timeNew = ui->dateTimeEdit_2->dateTime();
    // 计算相差天数
    // int days = timeOld.daysTo(timeNew);
    // 计算相差小时
    int second = timeOld.secsTo(timeNew);
    int days = (second / 3600) / 24;
    int hours = (second / 3600) % 24;
    ui->label->setText(QString("我们相爱了：" + QString::number(days))
                       + "天" + QString::number(hours) + "小时");
}

